package mamikeji.liaowa.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import mamikeji.liaowa.R;
import mamikeji.liaowa.bean.CircleTypeBean;

/**
 * Created by 廉冲-android开发 on 2017/9/19.
 */
public class CircleTypeGridAdapter extends BaseAdapter {
    List<CircleTypeBean.DataEntity> dataEntityList = new ArrayList<>();//数据集
    Context context;
    LayoutInflater inflater;
    OnItemClickListener mOnItemClickListener;

    public CircleTypeGridAdapter(List<CircleTypeBean.DataEntity> dayListBeanList, Context context) {
        this.dataEntityList = dayListBeanList;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void setList(List<CircleTypeBean.DataEntity> dayListBeanList) {
        this.dataEntityList = dayListBeanList;
        notifyDataSetChanged();
    }

    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }

    @Override
    public int getCount() {
        return dataEntityList.size();
    }

    @Override
    public Object getItem(int i) {
        return dataEntityList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_circle_type_grid, null);
            viewHolder = new ViewHolder();
            viewHolder.textView = (TextView) convertView.findViewById(R.id.textView_circle_type_item);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        CircleTypeBean.DataEntity bean = dataEntityList.get(position);

        viewHolder.textView.setText(bean.getType_name());
        viewHolder.textView.setBackgroundResource(bean.getIs_choice() == 1 ? R.drawable.shape_publish_circle_type_btn_bg_sel : R.drawable.shape_publish_circle_type_btn_bg_null);
        viewHolder.textView.setTextColor(context.getResources().getColor(bean.getIs_choice() == 1 ? R.color.color_app : R.color.color_text_333));
        return convertView;
    }

    public class ViewHolder {
        public TextView textView;
    }
}
